
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :Wing
	CreateTime:2008-03-04 14:47:09
*/
public class WarehouseCustomerSrv extends IHandler
{

	public WarehouseCustomerSrv() 
	{
		super();
	}
	private void deleteWarehouseCustomer(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		WarehouseCustomer obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = WarehouseCustomer.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveWarehouseCustomer(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		WarehouseCustomer obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = WarehouseCustomer.fetch();
    	}
    	else                     //update
    	{
    		obj = WarehouseCustomer.fetch(con,id);
    	}
		WarehouseCustomerPageData data = (WarehouseCustomerPageData)PageData.fromForm(context,WarehouseCustomerPageData.class);
		context.setValue("WarehouseCustomerPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listWarehouseCustomer(DBConnection con,SrvContext context,String path) throws Exception
	{
		WarehouseCustomerSearchEvent event = (WarehouseCustomerSearchEvent)SearchEvent.fromForm(context,WarehouseCustomerSearchEvent.class);
		context.setSessionValue("WarehouseCustomerSearchEvent",event);
		context.setNextUrl(path+"WarehouseCustomerList.jsp");
	}
	private void backWarehouseCustomer(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"WarehouseCustomerList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listWarehouseCustomer"))
		{
			listWarehouseCustomer(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewWarehouseCustomer"))
		{
			String id = context.getString("Id",null);
			WarehouseCustomer obj = WarehouseCustomer.fetch(con,id);
			context.setValue("WarehouseCustomer",obj);
			context.setNextUrl(path+"WarehouseCustomerView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteWarehouseCustomer"))
		{
			context.setErrorUrl(path+"WarehouseCustomerList.jsp");
			deleteWarehouseCustomer(con,context);
			backWarehouseCustomer(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddWarehouseCustomer"))
		{
			WarehouseCustomer obj = WarehouseCustomer.fetch();
			WarehouseCustomerPageData data = (WarehouseCustomerPageData)PageData.fromTable(obj,WarehouseCustomerPageData.class);
			context.setValue("WarehouseCustomerPageData",data);
			context.setNextUrl(path+"WarehouseCustomerEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateWarehouseCustomer"))
		{
			String id = context.getString("Id",null);
			WarehouseCustomer obj = WarehouseCustomer.fetch(con,id);
			WarehouseCustomerPageData data = (WarehouseCustomerPageData)PageData.fromTable(obj,WarehouseCustomerPageData.class);
			context.setValue("WarehouseCustomerPageData",data);
			context.setNextUrl(path+"WarehouseCustomerEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyWarehouseCustomer"))
		{
			String id = context.getString("Id",null);
			WarehouseCustomer obj = WarehouseCustomer.copy(WarehouseCustomer.fetch(con,id));
			WarehouseCustomerPageData data = (WarehouseCustomerPageData)PageData.fromTable(obj,WarehouseCustomerPageData.class);
			context.setValue("WarehouseCustomerPageData",data);
			context.setNextUrl(path+"WarehouseCustomerEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveWarehouseCustomer"))
		{
			context.setErrorUrl(path+"WarehouseCustomerEdit.jsp");
			saveWarehouseCustomer(con,context,loginContext);
			backWarehouseCustomer(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewWarehouseCustomer"))
		{
			context.setErrorUrl(path+"WarehouseCustomerEdit.jsp");
			saveWarehouseCustomer(con,context,loginContext);
			WarehouseCustomer obj = WarehouseCustomer.fetch();
			WarehouseCustomerPageData data = (WarehouseCustomerPageData)PageData.fromTable(obj,WarehouseCustomerPageData.class);
			context.setValue("WarehouseCustomerPageData",data);
			context.setNextUrl(path+"WarehouseCustomerEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListWarehouseCustomer"))
		{
			backWarehouseCustomer(con,context,path);
			return;
		}
		
		//add by Wing start

		//add by Wing end

		Logger.throwException("WarehouseCustomerSrv","unknown action_code="+action_code);
	}
}
